//
//  HMAudioPlayerTextViewController.m
//  HowToDo
//
//  Created by mynSoo on 2017/1/8.
//  Copyright © 2017年 KY. All rights reserved.
//

#import "HMAudioPlayerTextViewController.h"

typedef enum :NSInteger
{
    HeaderButtonTypeDismiss = 0,
    HeaderButtonTypeYinxiang = 1,
    HeaderButtonTypeYoudao = 2,
    HeaderButtonTypeShare = 3
}HeaderButtonType;

@interface HMAudioPlayerTextViewController ()

@property (nonatomic, weak) UIView *headerView;
@end

@implementation HMAudioPlayerTextViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self installUI];
}

- (void)installUI
{
    self.view.backgroundColor = [UIColor colorWithHex:0xfafafa];
    
    UIView *headerView = [self installHeaderView];
    UIView *contentView = [self installContentView];
    
    [self.view addSubview: headerView];
    [self.view addSubview: contentView];
    
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.right.offset(0);
        make.height.offset(64);
    }];
    
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headerView.mas_bottom);
        make.left.right.bottom.offset(0);
    }];
}

- (UIView *)installHeaderView
{
    UIView *headerView = [[UIView alloc]init];
    
    // headerView addSubview:<#(nonnull UIView *)#>
    
    UIButton *dismissBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [dismissBtn setImage:[UIImage imageNamed:@"new_audio_text_dismiss"] forState:UIControlStateNormal];
    
    [headerView addSubview:dismissBtn];
    
    [dismissBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20);
        make.left.offset(16);
        ;
    }];
    
    dismissBtn.tag = HeaderButtonTypeDismiss;
    
    [dismissBtn addTarget:self action:@selector(clickHeaderViewBtn:) forControlEvents:UIControlEventTouchDown];
    
    UIButton *shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [shareBtn setImage:[UIImage imageNamed:@"mini_mediaplayer_share_btn"] forState:UIControlStateNormal];
    
    [headerView addSubview:shareBtn];
    
    [shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-16);
        make.top.offset(20);
    }];
    [shareBtn addTarget:self action:@selector(clickHeaderViewBtn:) forControlEvents:UIControlEventTouchDown];
    
    shareBtn.tag = HeaderButtonTypeShare;
    
    UIButton *youdaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [youdaoBtn setImage:[UIImage imageNamed:@"new_audio_text_youdao"] forState:UIControlStateNormal];
    
    [headerView addSubview:youdaoBtn];
    
    [youdaoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(shareBtn.mas_left).offset(-16);
        make.top.offset(20);
    }];
    
    [youdaoBtn addTarget:self action:@selector(clickHeaderViewBtn:) forControlEvents:UIControlEventTouchDown];
    
    youdaoBtn.tag = HeaderButtonTypeYoudao;
    
    UIButton *yinxiangBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [yinxiangBtn setImage:[UIImage imageNamed:@"new_audio_text_yinxiang"] forState:UIControlStateNormal];
    
    [headerView addSubview:yinxiangBtn];
    
    [yinxiangBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(youdaoBtn.mas_left).offset(-16);
        make.top.offset(20);
    }];
    
    [yinxiangBtn addTarget:self action:@selector(clickHeaderViewBtn:) forControlEvents:UIControlEventTouchDown];
    
    yinxiangBtn.tag = HeaderButtonTypeYinxiang;
    
    UIView *sepratorView = [[UIView alloc]init];
    sepratorView.backgroundColor = [UIColor blackColor];
    [headerView addSubview:sepratorView];
    
    [sepratorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(1.0 / [UIScreen mainScreen].scale);
        make.left.right.offset(0);
        make.bottom.offset( -1.0 / [UIScreen mainScreen].scale);
    }];
    
    return headerView;
}

- (UIView *)installContentView
{
    UIView *contentView = [[UIView alloc]init];
    
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"empty_placeholder_90x90_"]];
  
    UILabel *msgLabel = [[UILabel alloc] init];
    msgLabel.text = @"该音频没有内容!";
    msgLabel.font = [UIFont systemFontOfSize:18];
    [msgLabel sizeToFit];

    [contentView addSubview:imageView];
    [contentView addSubview:msgLabel];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(100);
        make.centerX.offset(0);
    }];
    
    [msgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).offset(10);
        make.centerX.equalTo(imageView);
    }];
    
    return contentView;
}

#pragma mark - 触发
- (void)clickHeaderViewBtn:(UIButton *)sender
{
    switch (sender.tag) {
        case HeaderButtonTypeDismiss:{
            [self dismissViewControllerAnimated:YES completion:nil];
        }break;
        case HeaderButtonTypeYinxiang:{
            
        }break;
        case HeaderButtonTypeYoudao:{
        
        }break;
        case HeaderButtonTypeShare:{
        
        }break;
        default:{
        
        }break;
    }
}
@end
